(function (w) {
    let util = {
        isReceived: (ajax) =>
            ajax.readyState === 4 && ajax.status < 300 && ajax.status !== 0,
        isEmptyObject: (obj) => {
            for (const key in obj) {
                if (Object.hasOwnProperty.call(obj, key)) {
                    return false;
                }
            }
            return true;
        },
        str2Html: (str) => {
            let box = document.createElement('div');
            box.innerHTML = str;
            return box.lastElementChild;
            //修复bug：lastChile有可能是文本对象
        },
        formatDate: (time) => {
            const dateTime = new Date(time);
            const year = dateTime.getFullYear();
            const month = dateTime.getMonth() + 1;
            const date = dateTime.getDate();
            const hour = dateTime.getHours();
            const minute = dateTime.getMinutes();
            const second = dateTime.getSeconds();
            return `${year}年${month}月${date}日&nbsp;&nbsp;${add0(hour)}:${add0(minute)}:${add0(second)}`;
        },
        getCurrRootUrl: () => {
            return pattern_forRoot.exec(w.location.href)[0];
        },
        tagFilter: (str) => {
            return str
                .replace(/&/g, '&amp;')
                .replace(/ /g, '&nbsp;')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;')
                .replace(/"/g, '&quot;')
                .replace(/'/g, '&#39;');
        }
    };
    function add0(s) {
        return s < 10 ? '0' + s : s;
    }
    w.util = util;
})(window);
